<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/templates/common/taglib.jsp"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<title>${title}</title>
<%@include file="/WEB-INF/templates/common/common.jsp"%>
<script type="text/javascript" src="${basePath}/static/page/js/jqPaginator.js"></script>
<script type="text/javascript" src="${basePath}/static/My97DatePicker/WdatePicker.js"></script>
<script  type="text/javascript" src="${basePath}/static/js/util.js"></script>

<script type="text/javascript" src="${basePath}/static/layer/layer.js"></script>
<link href="${basePath}/static/layer/layer_style.css" rel="stylesheet"
	type="text/css">
<!-- <script  type="text/javascript" src="${basePath}/static/print/js/photo.js"></script> -->
<script type="text/javascript" src="${basePath}/static/js/ajaxfileupload.js"></script>
</head>
<body>

</head>
<body>
 <!--头部-->
 <%@include file="/WEB-INF/templates/common/header.jsp"%>

<!------导航条-->
 <%@include file="/WEB-INF/templates/common/navigation.jsp"%>

<div class="list_main lay_out">
 <div class="list_DH">
    <!--打印模块导航栏-->
 <%@include file="/WEB-INF/templates/common/printnav.jsp"%>
 </div>
 <div class="list_NR">
  <div class="loc">
   <h3>邮寄详情</h3>
  </div>
 
  <div class="list_con_table"> 
	 <div class="search_table">
    <ul id="table_ul">
    <li class="Label_1" style="width:15%">ID号：&nbsp;</li>
    <li class="Label_2" style="width:16%"><input class="input_box" type="text" maxlength="40" id='mrId'  /></li>
    
     <li class="Label_1" style="width:12%">住院次数：&nbsp;</li>
    <li class="Label_2" style="width:16%"><input class="input_box" type="text" maxlength="40" id='visitNumber'  /></li>
    
     <li class="Label_1">出院日期：</li>
     <li class="Label_2" style="width:27%;text-align:left">
     <input style="width:44%;margin-left:5px" class="input_box" id="timeStart" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' /> 
     - <input style="width:44%" class="input_box" id="timeEnd" onfocus="WdatePicker({dateFmt:'yyyy-MM-dd'})" type="text"  name=''  value='' />
     </li>
    
    <li class="Label_5">
	   <a onclick="findMr(1,10)">查询</a>
	  <!--  <a onclick="exportPrintDetailToExcel()">导出</a> -->
    </li>
    </ul>
  </div>
  	<table class="Search_tableList" cellpadding="0" cellspacing="0">
		      <tr>
		      <td class="tdLabel_4">姓名</td>
		      <td class="tdLabel_4">ID号</td>
		      <td class="tdLabel_4">住院次数</td>
		      <td class="tdLabel_4">病案号</td>
		       <td class="tdLabel_4">打印份数</td>
		      <td class="tdLabel_4">邮费</td>
		      <td class="tdLabel_4">登记日期</td>
		      <td class="tdLabel_4">打印状态</td>
		      <td class="tdLabel_4">光盘刻录</td>
		       <td class="tdLabel_4">操作</td>
		      </tr>
		      <tr id="loading" style="height:50px;display:none">
	             <td colspan="9" align="center" ><img src="${basePath}/static/layer/skin/default/loading-2.gif"></td>
	          </tr>
		      <tbody id="tbody">
		      </tbody>
     </table>
    <div class="pageList">
       <ul class="pagination clearfix" id="page_plus"></ul>
       <div class="pagination">
            <div>总共：<b id="totalPage">0</b> 条信息    当前页是第 <b id="currentPage">0/0</b>　页</div>
       </div>          
    </div>
  
 </div>
</div>
</div>
<input type="hidden" value="${firstGuid}">
<!--页脚部分-->
<%@include file="/WEB-INF/templates/common/footer.jsp"%>
 <script>
 function findMr(pageNo,pageSize){
		var mrId=$("#mrId").val();	
		var visitNumber = $("#visitNumber").val();
		var startTime=$("#timeStart").val();
		var endTime=$("#timeEnd").val();
		if((startTime==null || startTime=="")&&(endTime==null || endTime=="")
				&&(visitNumber==null || visitNumber=='')&&(mrId==null || mrId=='')){
			layer.alert('查询条件不能为空', {icon: 0}); 
			return;
		}
		//{"hospitalizationNotes":[{"mr_id":"0158981","id_number":"130625284798787009","treatment_type_name":"住院","out_hospital_date":"2017-09-24","name":"赵尊号","id":5,"first_level_medical_guid":"ad820cdb37fc493aa820caa4c36c8cfd","hospital_name":"山东省立医院"}],"medRecordQuery":{"currentStartNum":0,"totalPages":1,"name":"赵尊号","pageSize":1,"currentPage":1,"totalCounts":1}}
		//jQuery.support.cors = true;
		$.ajax({
			type:"post",
			url:"${printPath}/mail/selectMailRecordByCondition",
			data:{visitNumber:visitNumber,mrId:mrId,startTime:startTime,endTime:endTime,pageNo:pageNo, pageSize:pageSize},
			beforeSend:function(){
				$("#tbody").html("");
				$("#loading").show();
			},

			success:function(data){
				console.log(data);
				$("#loading").hide();
			if(data.success) {
				if(data!=null && data!=""){
					
					initPage(data.data.totalCount,pageSize,pageNo);
					var mailList=data.data.mailList;
					var html="";
				 	for(var i=0;i<mailList.length;i++){
				 		var mail=mailList[i];
				 		var patient_name = mail.patient_name;
				 		if (patient_name == null) {
				 			patient_name = '';
				 		}
				 		var print_copies = mail.print_copies;
				 		if (print_copies == null) {
				 			print_copies = '';
				 		}
				 		var postage = mail.postage;
				 		if(postage == null) {
				 			postage = '';
				 		}
				 		
				 		var onlyId = mail.only_id;
				 		if(onlyId == null) {
				 			onlyId = '';
				 		}
				 		var burnCdStatus = "";
				 		if (mail.burn_cd_status == 0) {
				 			burnCdStatus = "否";
				 		} else if (mail.burn_cd_status == 1) {
				 			burnCdStatus = "是";
				 		}
				 		
				 		
				 		var printStatus = mail.print_status;
				 		var printStatusStr = "";
						html+="<tr>"+
						      " <td  class='tdLabel_5'>"+patient_name+"</td>"+
						   	  " <td  class='tdLabel_5'>"+mail.mr_id+"</td>"+
						   	  " <td  class='tdLabel_5'>"+mail.visit_number+"</td>"+
						   	" <td  class='tdLabel_5'>"+onlyId+"</td>"+
						      " <td  class='tdLabel_5'>"+print_copies+"</td>"+
						      " <td  class='tdLabel_5'>"+postage+"</td>"+
						      " <td  class='tdLabel_5'>"+mail.record_date+"</td>";
						      if (printStatus == 0) {
							    	html+= "<td  class='tdLabel_5'>未打印</td>";
							    	printStatusStr = "修改为已打印";
							      } else{
							    	  html+= "<td  class='tdLabel_5'>已打印</td>";
							    	  printStatusStr = "修改为未打印";
							     } 
						      
						      html+="<td  class='tdLabel_5'>"+burnCdStatus+"</td>";
						      html+= "<td  class='tdLabel_5'><a class='int' mrId="+mail.mr_id+" visitNumber="+mail.visit_number+" target='_blank' onclick='print(this)'>打印</a>"+
						      "<a class='int' target='_blank' printStatus="+mail.print_status+" id="+mail.id+"  onclick='updateStatus(this)'>"+printStatusStr+"</a>"+
						      "<a class='int' target='_blank' id="+mail.id+" onclick='deleteById(this)'>删除</a></td>";
						     
						      
						      html+="</tr>";
					}
					$("#tbody").html(html);
				}else{
					layer.alert('查询数据为空', {icon: 5}); 
					$("#tbody").html("");
					
				}			
			} else{
				layer.alert(data.msg, {icon: 5}); 
			}
			}
		})
	}
	
	function page(currentPage,totalCounts){
	
	var totalCounts = totalCounts;
		var pageSize = 10;
		var totalPages = Math.ceil(totalCounts/pageSize);
		$("#ston_page_msg").text(totalPages);
		
		$("#Pagination").pagination(totalPages,{
		current_page:currentPage,
	  callback: function (page_index,jp) {
		findMr(page_index,pageSize);
	  } 
	  
	  });
	}
	
//分页
	function initPage(totalCounts,pageSize,currentPage){
		 var visiblePages = 5;
		 var totalPages =Math.ceil(totalCounts/pageSize);
		 $("#totalPage").html(totalCounts);
		 if(totalCounts < 1){
		 	$("#currentPage").html(0+"/"+totalPages);
		 	$("#page_plus").html("");
		 	return;
		 }
		 
      $("#currentPage").html(currentPage+"/"+totalPages);
      
		 $('#page_plus').jqPaginator({

		        totalCounts: totalCounts,
		        pageSize:pageSize,
		        visiblePages: visiblePages,
		        currentPage: currentPage,

		        first:'<li class="first"><a href="javascript:void(0);">首页</a></li>',
		        prev: '<li class="prev"><a href="javascript:void(0);">上一页</a></li>',
		        next: '<li class="next"><a href="javascript:void(0);">下一页</a></li>',
		        last: '<li class="last"><a href="javascript:void(0);">末页</a></li>',
		        page: '<li class="page"><a href="javascript:void(0);">{{page}}</a></li>',
		        onPageChange: function (page,type) {
		        	if(type !='init'){
		        		findMr(page,pageSize);
			        }
		        }
		    });

	}	

  
  function print(obj) {
	var mrId = $(obj).attr("mrId");
	var visitNumber = $(obj).attr("visitNumber");
	$.ajax({
		type:"get",
		url:"${corePath}/medrecord/queryMedrecordOfMailPrintByAjax",
		data:{visitNumber:visitNumber,mrId:mrId},
		success:function(data){
			console.log(data);
		if(data.success) {
			if(data!=null && data!=""){
				var hospNote = data.data;
				if (hospNote.length > 0) {
					var firstGuid = hospNote[0].first_level_medical_guid;
					location = "${basePath}/print/printToPageinfo?visitGuid="+firstGuid+"&applyReason=1"
				} else{
					layer.alert('查询数据为空!', {icon: 5}); 
				}
			}else{
				layer.alert('查询数据为空!', {icon: 5}); 
									
			}			
		} else{
			layer.alert(data.msg, {icon: 5}); 
		}
		}
	})
  }
  
  function deleteById(obj) {
	  var id = $(obj).attr("id");
	   $.ajax({
		type:"get",
		url:"${printPath}/mail/deleteById",
		data:{id:id},
		success:function(data){
			console.log(data);
		if(data.success) {
			layer.alert(data.msg,{icon:1}); 
			$(obj).parent().parent().remove();
			
		} else{
			layer.alert(data.msg, {icon: 5}); 
		}
		}
	}) 
  } 
  
  function updateStatus(obj) {
	  var id = $(obj).attr("id");
	  var printStatus = $(obj).attr("printStatus");
	  console.log("printStatus="+printStatus);
	  if(printStatus == 0) {
		  printStatus=1;
	  } else{
		  printStatus=0;
	  }
	
	  console.log("printStatus="+printStatus);
	  
	  $.ajax({
			type:"post",
			url:"${printPath}/mail/updatePrintStatusById",
			data:{id:id, printStatus:printStatus},
			success:function(data){
				console.log(data);
			if(data.success) {
				layer.alert(data.msg,{icon:1}); 
				$(obj).attr("printStatus", printStatus);
				
				  if (printStatus == 0) {
					  $(obj).text("修改为已打印");
					  $(obj).parent().prev().text("未打印");
				  } else{
				    	 $(obj).text("修改为未打印");
				    	 $(obj).parent().prev().text("已打印");
				     } 
				 
			} else{
				layer.alert(data.msg, {icon: 5}); 
			}
			}
		}) 
	  
	  
	  
  }
  
 </script>

</body>
</html>
